import configparser
import os
from dotenv import load_dotenv

from core.consts import CONFIG_PATH

# load .env from project root
load_dotenv(os.path.join
            (os.path.dirname
             (os.path.dirname(__file__)), '.env'))

# BASE_URL = os.getenv("BASE_URL", "http://localhost:8000")
BASE_URL = os.getenv("BASE_URL", "http://api.yesapi.net")
TOKEN = os.getenv("TOKEN", "")
TIMEOUT = int(os.getenv("TIMEOUT", "5"))
ENV = os.getenv("ENV", "test")


class Config(object):
    def __init__(self, filename="config.ini"):
        self.cf = configparser.ConfigParser()
        self.log_path = os.path.join(CONFIG_PATH, filename)
        self.cf.read(self.log_path)

    def get_conf(self, section, option):
        return self.cf.get(section, option)

    def set_conf(self, section, option):
        self.cf.set(section, option)
        with open(self.log_path, 'w+') as f:
            return self.cf.write(f)

    def add_section(self, section):
        self.cf.add_section(section)
        with open(self.log_path, 'w+') as f:
            return self.cf.write(f)

    def get_runtime(self, option):
        return self.get_conf("runtime", option)

    def get_email(self, option):
        return self.get_conf("email", option)

    def get_wamp(self, option):
        """获取wamp 信息"""
        return self.get_conf("wamp", option)





